package com.functest.orm

import com.functest.framework.BaseFunctionalTest
import com.functest.orm.legacy.SimpleMapper
import org.testng.annotations.Test

/**
 * @author: DavydovMD
 * Date: 03.09.13
 * Time: 14:51
 */
class SimpleMapperTest extends BaseFunctionalTest{
    @Test
    void testConstructorWithEnricher(){
        Map dbm =  [b:'a',d:'c']
        SimpleMapper mapper = new SimpleMapper(dbMapping: dbm,enrichClosure: {[e:'f']} as Closure<Map>)
        assert mapper.dbMapping ==   dbm
        assert mapper.mapRow([a:1, c:2])==[b:1, d:2, e:'f']

    }

    @Test
    void testConstructorNoEnricher(){
        SimpleMapper mapper = new SimpleMapper(dbMapping: [b:'a',d:'c'])
        assert mapper.mapRow([a:1, c:2])==[b:1, d:2]
        assert mapper.allFields == '"a","c"'
        assert mapper.mapRow([a:1], {return [f:32]} as Closure) == [b:1, f:32]
    }

    @Test
    void testMapForConstructor(){
        SimpleMapper mapper = new SimpleMapper(dbMapping: [b:'a',d:'c'])
        assert mapper.mapRowForConstructor([a:1,d:null],{['e':32]} as Closure)==[b:1,e:32]
    }





}
